﻿package plugin.bagN.control
{
    import cmd.*;
    import com.core.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import consts.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.ui.*;
    import flash.utils.*;
    import manager.*;
    import morn.core.components.*;
    import morn.core.handlers.*;
    import plugin.bagN.*;
    import plugin.storehouse.*;
    import uiresource.bag.*;
    import view.*;
    import view.appDrag.*;
    import view.message.*;
    import view.mornExtends.*;
    import view.uilt.*;
    import vo.*;

    public class BagCtrl extends BagNUI implements IRoot
    {
        private var mUIBase:Bag;
        private var _cfgitems:Object;
        private var _tab:int = 1;
        private var _cfgtools:Object;
        private var isShowmenuelist:Boolean = true;
        private var clicktime:int = 0;
        private var curtime:int = 0;
        private var _timeID:uint = 0;
        private var bagtype:int = 0;
        private var _maxcount:int = 98;
        private var _toolArray:Array = null;
        private var _usercount:int = 0;
        private var _emptycount:int = 0;
        private var _tbagArr:Object;
        private var _clickindex:int = -1;

        public function BagCtrl(param1:Bag)
        {
            this._cfgitems = ConfigDictionary.data.item;
            this.mUIBase = param1;
            return;
        }// end function

        override protected function createChildren() : void
        {
            viewClassMap["uiresource.bag.TbagUI"] = TbagUI;
            viewClassMap["uiresource.bag.bagitemUI"] = BagitemCtrl;
            loadUI("BagN.xml");
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            _useMenu.visible = false;
            sellbox.visible = false;
            var _loc_1:* = Control.create(BagControl, this);
            ModelProxy.addObserver("bag", _loc_1);
            menuelist.array = [{label:"使用"}, {label:"丢弃"}, {label:"拆分"}, {label:"批量"}];
            this.addEvent();
            (this.getChildByName("tab1") as Button).selected = true;
            this.init(UserData.getBagData());
            getgoldbtn.label = "提取元宝";
            this.getVip();
            return;
        }// end function

        private function addEvent() : void
        {
            getgoldbtn.addEventListener(MouseEvent.CLICK, this.getgoldHandler);
            openhs.addEventListener(MouseEvent.CLICK, this.openHuisho);
            shopbtn.addEventListener(MouseEvent.CLICK, this.shopHandler);
            tidybtn.addEventListener(MouseEvent.CLICK, this.tidyHandler);
            baitan.addEventListener(MouseEvent.CLICK, this.baitanHandler);
            closebtn.addEventListener(MouseEvent.CLICK, this.closeclickHnalder);
            gold.addEventListener(MouseEvent.ROLL_OVER, this.goldOverHandler);
            goldtxt.addEventListener(MouseEvent.ROLL_OVER, this.goldOverHandler);
            bgold.addEventListener(MouseEvent.ROLL_OVER, this.bgoldOverHandler);
            bgoldtxt.addEventListener(MouseEvent.ROLL_OVER, this.bgoldOverHandler);
            bybtxt.addEventListener(MouseEvent.ROLL_OVER, this.byuanbaoOverHandler);
            byuanbao.addEventListener(MouseEvent.ROLL_OVER, this.byuanbaoOverHandler);
            ybtxt.addEventListener(MouseEvent.ROLL_OVER, this.yuanbaoOverHandler);
            yuanbao.addEventListener(MouseEvent.ROLL_OVER, this.yuanbaoOverHandler);
            gold.addEventListener(MouseEvent.ROLL_OUT, this.RollOunHandler);
            goldtxt.addEventListener(MouseEvent.ROLL_OUT, this.RollOunHandler);
            bgold.addEventListener(MouseEvent.ROLL_OUT, this.RollOunHandler);
            bgoldtxt.addEventListener(MouseEvent.ROLL_OUT, this.RollOunHandler);
            bybtxt.addEventListener(MouseEvent.ROLL_OUT, this.RollOunHandler);
            byuanbao.addEventListener(MouseEvent.ROLL_OUT, this.RollOunHandler);
            ybtxt.addEventListener(MouseEvent.ROLL_OUT, this.RollOunHandler);
            yuanbao.addEventListener(MouseEvent.ROLL_OUT, this.RollOunHandler);
            tbag.getAlbtnl.addEventListener(MouseEvent.CLICK, this.getAlllList);
            menuelist.selectHandler = new Handler(this.menueselect);
            AppDragMgr.addEventListener(AppDragEvent.DRAG, this.clingyHandler);
            var _loc_1:int = 1;
            while (_loc_1 <= 5)
            {
                
                (this.getChildByName("tab" + _loc_1) as Button).clickHandler = new Handler(this.tabHandler, [_loc_1]);
                _loc_1++;
            }
            return;
        }// end function

        protected function openHuisho(event:MouseEvent) : void
        {
            ModelProxy.change("plugin", "open", {target:"zbhsy"});
            return;
        }// end function

        public function tabHandler(param1:int) : void
        {
            var _loc_2:int = 1;
            while (_loc_2 <= 5)
            {
                
                (this.getChildByName("tab" + _loc_2) as Button).selected = false;
                _loc_2++;
            }
            (this.getChildByName("tab" + param1) as Button).selected = true;
            this.bagtype = param1;
            ModelProxy.change("data", "bagtype", this.bagtype);
            this.change(param1);
            return;
        }// end function

        private function change(param1:int) : void
        {
            var _loc_2:Object = null;
            var _loc_3:String = null;
            var _loc_4:String = null;
            var _loc_6:int = 0;
            var _loc_7:Object = null;
            this._tab = param1;
            var _loc_5:Array = [];
            if (param1 == 1)
            {
                mlist.array = this._toolArray;
            }
            else if (param1 == 2)
            {
                for each (_loc_2 in this._toolArray)
                {
                    
                    if (_loc_2[4] && _loc_2[4].itemtype == 1)
                    {
                        _loc_5.push(_loc_2);
                    }
                }
            }
            else if (param1 == 3)
            {
                for each (_loc_2 in this._toolArray)
                {
                    
                    _loc_3 = "";
                    if (_loc_2[4])
                    {
                        _loc_3 = _loc_2[4].itemid + "";
                    }
                    _loc_4 = _loc_3.substr(0, 3);
                    if (_loc_2[4] && _loc_2[4].itemtype == 2 && _loc_2[4].leixing == "药品")
                    {
                        _loc_5.push(_loc_2);
                    }
                }
            }
            else if (param1 == 4)
            {
                for each (_loc_2 in this._toolArray)
                {
                    
                    _loc_3 = "";
                    if (_loc_2[4])
                    {
                        _loc_3 = _loc_2[4].itemid + "";
                    }
                    _loc_4 = _loc_3.substr(0, 3);
                    if (_loc_2[4] && _loc_2[4].itemtype == 2 && _loc_2[4].leixing != "药品" && _loc_2[4].leixing != "其他")
                    {
                        _loc_5.push(_loc_2);
                    }
                }
            }
            else if (param1 == 5)
            {
                for each (_loc_2 in this._toolArray)
                {
                    
                    _loc_3 = "";
                    if (_loc_2[4])
                    {
                        _loc_3 = _loc_2[4].itemid + "";
                    }
                    _loc_4 = _loc_3.substr(0, 3);
                    if (_loc_2[4] && _loc_2[4].itemtype == 2 && _loc_2[4].leixing == "其他")
                    {
                        _loc_5.push(_loc_2);
                    }
                }
            }
            if (param1 != 1)
            {
                _loc_6 = _loc_5.length;
                while (_loc_6 < 98)
                {
                    
                    if (_loc_6 < 0)
                    {
                    }
                    else
                    {
                        _loc_7 = new Object();
                        _loc_7.index = this._toolArray[_loc_6].index;
                        _loc_7.lock = this._toolArray[_loc_6].lock;
                        if (_loc_6 < 98)
                        {
                            _loc_5.push(_loc_7);
                        }
                    }
                    _loc_6++;
                }
                mlist.array = _loc_5;
            }
            mlist.renderHandler = new Handler(this.mlistrender);
            return;
        }// end function

        private function clingyHandler(event:AppDragEvent) : void
        {
            var _loc_2:int = 0;
            var _loc_5:Point = null;
            var _loc_6:Point = null;
            var _loc_7:Point = null;
            var _loc_8:Point = null;
            if (!(event.targetObj is BagitemCtrl))
            {
                return;
            }
            event.stopImmediatePropagation();
            if (event.itemData.index == _loc_2)
            {
                return;
            }
            _loc_2 = -1;
            var _loc_3:* = mlist.startIndex;
            var _loc_4:* = _loc_3;
            while (_loc_4 < _loc_3 + mlist.cells.length)
            {
                
                if (mlist.getCell(_loc_4).hitTestPoint(event.hitPoint.x, event.hitPoint.y, true))
                {
                    _loc_2 = _loc_4;
                    break;
                }
                _loc_4++;
            }
            if (_loc_2 == -1)
            {
                _loc_5 = UIGlobel.pointsDic["setskill"];
                _loc_6 = event.hitPoint;
                if (PluginManager.instance.getPluginState("business") == "open")
                {
                    _loc_7 = PluginManager.instance.getPluginPos("business");
                    _loc_8 = PluginManager.instance.getPluginSize("business");
                    if (_loc_6.x > _loc_7.x && _loc_6.x < _loc_7.x + _loc_8.x && _loc_6.y > _loc_7.y && _loc_6.y < _loc_7.y + _loc_8.y)
                    {
                        ModelProxy.change("business", "clientAddItem", event.itemData);
                    }
                }
                else if (_loc_6.x > _loc_5.x && _loc_6.x < _loc_5.x + 46 * 12 && _loc_6.y > _loc_5.y && _loc_6.y < _loc_5.y + 46 && event.itemData[2] == 2)
                {
                    ModelProxy.change("fastlist", "dragComplate", {point:_loc_6, data:event.itemData[4]});
                }
                else
                {
                    this.throwByIndex(event.itemData);
                }
                return;
            }
            _loc_2++;
            PluginManager.instance.sendToServer("bag", CMDBag.Swap, {index:event.itemData.index, toindex:_loc_2});
            return;
        }// end function

        private function menueselect(param1:int) : void
        {
            var _loc_2:Object = null;
            var _loc_3:Number = NaN;
            if (this._clickindex < 0)
            {
                return;
            }
            var _loc_4:* = menuelist.selectedIndex;
            var _loc_5:* = this._toolArray[this._clickindex];
            if (this._toolArray[this._clickindex][4] == null)
            {
                return;
            }
            if (_loc_4 == 0)
            {
                if (int(_loc_5[4].cls) == 4)
                {
                    if (_loc_5[4].buffertype == 100)
                    {
                        ModelProxy.change("movetips", "error", "经验珠未满不能使用");
                        return;
                    }
                    DialogMgr.instance.open(AppDialog.JUHUNZHU, _loc_5);
                }
                else
                {
                    _loc_2 = ModelProxy.getValue("data", "toolcd");
                    _loc_3 = _loc_2[_loc_5[4].itemid];
                    if (getTimer() > _loc_3 || int(_loc_3) == 0)
                    {
                        ModelProxy.change("plugin", "useitem", _loc_5);
                    }
                }
            }
            else if (_loc_4 == 1)
            {
                this.throwByIndex(_loc_5);
            }
            else if (_loc_4 == 2)
            {
                if (_loc_5 && _loc_5[1] > 1 && int(_loc_5[4].overlying) > 1)
                {
                    DialogMgr.instance.open(AppDialog.EXPLODE_DIALOG, _loc_5);
                }
                else
                {
                    ModelProxy.change("movetips", "error", "无法拆分");
                }
            }
            else if (_loc_4 == 3)
            {
                _loc_2 = ModelProxy.getValue("data", "toolcd");
                _loc_3 = _loc_2[_loc_5[4].itemid];
                if (getTimer() > _loc_3 || int(_loc_3) == 0)
                {
                    if (this._cfgtools == null)
                    {
                        this._cfgtools = ConfigDictionary.data.item;
                    }
                    this.sureUseItem(_loc_5);
                }
            }
            _useMenu.visible = false;
            menuelist.selectedIndex = -1;
            this.clickitem2(null);
            return;
        }// end function

        public function throwByIndex(param1:Object) : void
        {
            if (ModelProxy.getValue("data", "issafe"))
            {
                ModelProxy.change("movetips", "error", "安全区域不能丢弃物品");
            }
            else if (int(param1[4].bind) == 1 || int(param1[2]) == 1 && int(param1[4].uselv) <= 70 && int(param1[4].reinlv) < 1)
            {
                if (this.isShowmenuelist)
                {
                    Alert2.show("丢弃该道具将直接销毁", "", ["确定", "取消"], this.throwItem, param1, false, true, true);
                }
                else
                {
                    PluginManager.instance.sendToServer("bag", CMDBag.GiveUpItem, param1.index);
                    ModelProxy.change("qianghua", "initpanel", null);
                    ModelProxy.change("data", "changeid", param1[4].itemid);
                }
            }
            else if (param1[4].level >= 1)
            {
                DialogMgr.instance.open(AppDialog.DROP_DIALOG, [param1, this.sureThrow, "确认丢弃"]);
            }
            else
            {
                PluginManager.instance.sendToServer("bag", CMDBag.GiveUpItem, param1.index);
                ModelProxy.change("qianghua", "initpanel", null);
                ModelProxy.change("data", "changeid", param1[4].itemid);
            }
            return;
        }// end function

        private function throwItem(param1:int, param2:Object) : void
        {
            if (param1 == 0)
            {
                PluginManager.instance.sendToServer("bag", CMDBag.GiveUpItem, param2.index);
                ModelProxy.change("qianghua", "initpanel", null);
                ModelProxy.change("data", "changeid", param2[4].itemid);
            }
            else if (param1 == 100)
            {
                this.isShowmenuelist = false;
                PluginManager.instance.sendToServer("bag", CMDBag.GiveUpItem, param2.index);
                ModelProxy.change("qianghua", "initpanel", null);
                ModelProxy.change("data", "changeid", param2[4].itemid);
            }
            else if (param1 == 101)
            {
                this.isShowmenuelist = false;
            }
            return;
        }// end function

        private function sureUseItem(param1:Object) : void
        {
            if (param1 && param1[0] == 240202063)
            {
                ModelProxy.change("movetips", "error", "未解封不能直接使用");
                return;
            }
            PluginManager.instance.playItemSound(param1[4]);
            if (int(param1[4].cls) == 4)
            {
                if (param1[4].buffertype == 100)
                {
                    ModelProxy.change("movetips", "error", "经验珠未满不能使用");
                    return;
                }
                DialogMgr.instance.open(AppDialog.JUHUNZHU, param1);
            }
            else if (int(param1[4].shuangji) == 1)
            {
                if (param1[4].buffertype == 8)
                {
                    if (ItemUilt.getVipLevelparam("eatexp") == -1 || ItemUilt.getVipLevelparam("eatexp") + Constant.EXP_PILL_DAILY_COUNT - (UserData.getOnlineData("EXP_PILL_EVERYDAY_USE_TIME") + UserData.getOnlineData("VIP_DAY_EXP_PILL_USE_COUNT")) > 0)
                    {
                        ModelProxy.change("data", "recycle", 1);
                    }
                }
                PluginManager.instance.sendToServer("bag", CMDBag.UseAllItem, param1.index);
                if (param1[4] && param1[4].buffertype == 8)
                {
                    if (ItemUilt.getVipLevelparam("eatexp") == -1 || ItemUilt.getVipLevelparam("eatexp") + Constant.EXP_PILL_DAILY_COUNT - (UserData.getOnlineData("EXP_PILL_EVERYDAY_USE_TIME") + UserData.getOnlineData("VIP_DAY_EXP_PILL_USE_COUNT")) > 0)
                    {
                        ModelProxy.change("data", "recycle", 1);
                    }
                }
            }
            else
            {
                ModelProxy.change("plugin", "useitem", param1);
            }
            ModelProxy.change("data", "changeid", param1[4].itemid);
            return;
        }// end function

        public function sureThrow(param1:Object) : void
        {
            PluginManager.instance.sendToServer("bag", CMDBag.GiveUpItem, param1.index);
            ModelProxy.change("qianghua", "initpanel", null);
            ModelProxy.change("data", "changeid", param1[4].itemid);
            return;
        }// end function

        private function sureallUseItem(param1:Object) : void
        {
            PluginManager.instance.playItemSound(param1[4]);
            PluginManager.instance.sendToServer("bag", CMDBag.UseAllItem, param1.index);
            ModelProxy.change("data", "changeid", param1[4].itemid);
            return;
        }// end function

        protected function closeclickHnalder(event:MouseEvent) : void
        {
            if (PluginManager.instance.getPluginState("suishenshop") == "open")
            {
                PluginManager.instance.closePlugin("suishenshop");
            }
            ModelProxy.change("plugin", "close", "bag");
            return;
        }// end function

        public function closePanel() : void
        {
            this.mUIBase.close();
            return;
        }// end function

        public function closeComplete() : void
        {
            ModelProxy.change("data", "selling", false);
            Mouse.cursor = MouseCursor.AUTO;
            sellbox.visible = false;
            if (GlobalLayer.instance.root.hasEventListener(MouseEvent.CLICK))
            {
                GlobalLayer.instance.root.removeEventListener(MouseEvent.CLICK, this.sellClickHandler);
            }
            return;
        }// end function

        protected function getAlllList(event:MouseEvent) : void
        {
            PluginManager.instance.sendToServer("bag", CMDBag.Tbag, null);
            return;
        }// end function

        public function chushou() : void
        {
            if (!ModelProxy.getValue("data", "selling"))
            {
                Mouse.cursor = "sell";
                ModelProxy.change("data", "selling", true);
                sellbox.visible = true;
                GlobalLayer.instance.root.addEventListener(MouseEvent.CLICK, this.sellClickHandler);
            }
            else
            {
                ModelProxy.change("data", "selling", false);
                Mouse.cursor = MouseCursor.AUTO;
                sellbox.visible = false;
                if (GlobalLayer.instance.root.hasEventListener(MouseEvent.CLICK))
                {
                    GlobalLayer.instance.root.removeEventListener(MouseEvent.CLICK, this.sellClickHandler);
                }
            }
            return;
        }// end function

        public function sellItem(param1:Object) : void
        {
            if (param1[4].level >= 30)
            {
                DialogMgr.instance.open(AppDialog.DROP_DIALOG, [param1, this.sureSell]);
            }
            else
            {
                this.sureSell(param1);
            }
            return;
        }// end function

        private function sureSell(param1:Object) : void
        {
            PluginManager.instance.sendToServer("shop", CMDShop.Sell, param1.index);
            return;
        }// end function

        protected function selldoubleClickHandler(event:MouseEvent = null) : void
        {
            if (!ModelProxy.getValue("data", "selling"))
            {
            }
            else
            {
                this.chushou();
            }
            return;
        }// end function

        protected function sellClickHandler(event:MouseEvent) : void
        {
            if (getTimer() - this.clicktime < 300)
            {
                this.selldoubleClickHandler();
                return;
            }
            this.clicktime = getTimer();
            if (!ModelProxy.getValue("data", "selling"))
            {
            }
            else
            {
                ModelProxy.change("movetips", "error", "请点击背包中的物品出售，双击背包外区域退出出售状态");
            }
            return;
        }// end function

        protected function RollOunHandler(event:MouseEvent) : void
        {
            ModelProxy.change("tips", "state", "close");
            return;
        }// end function

        protected function yuanbaoOverHandler(event:MouseEvent) : void
        {
            var _loc_2:* = UserData.getBagData();
            ModelProxy.change("tips", "normal", "<font color = \'#01B0F1\'>您拥有【元宝】：" + _loc_2.money + "</font>\n" + "<font color = \'#009900\'>【元宝】可用于购买商城中的元宝道具。</font>\n" + "<font color = \'#DDC026\'>【元宝】通过充值或参加特定活动获得。</font>");
            return;
        }// end function

        protected function byuanbaoOverHandler(event:MouseEvent) : void
        {
            var _loc_2:* = UserData.getBagData();
            ModelProxy.change("tips", "normal", "<font color = \'#01B0F1\'>您拥有【礼券】：" + _loc_2.bonus + "</font>\n" + "<font color = \'#009900\'>【礼券】可用于购买商城中的礼券道具。</font>\n" + "<font color = \'#DDC026\'>【礼券】通过参加游戏中的各种线上活动、在线活动获得。</font>");
            return;
        }// end function

        protected function bgoldOverHandler(event:MouseEvent) : void
        {
            var _loc_2:* = UserData.getBagData();
            ModelProxy.change("tips", "normal", "<font color = \'#01B0F1\'>您拥有【绑定金币】:" + _loc_2.bgold + "</font>\n" + "<font color = \'#009900\'>【绑定金币】可用于塔防副本、伏魔任务、购买药品、强化装备、升级法神。</font>\n" + "<font color = \'#DDC026\'>【绑定金币】小怪掉落、挖矿任务等途径获得。</font>");
            return;
        }// end function

        protected function goldOverHandler(event:MouseEvent) : void
        {
            var _loc_2:* = UserData.getBagData();
            ModelProxy.change("tips", "normal", "<font color = \'#01B0F1\'>您拥有【金币】:" + _loc_2.gold + "</font>\n" + "<font color = \'#009900\'>【金币】可用于塔防副本、伏魔任务、购买药品、强化装备、升级法神、玩家交易。</font>\n" + "<font color = \'#DDC026\'>【金币】每日祈祷、BOSS掉落等途径获得。</font>");
            return;
        }// end function

        protected function recebtnHandler(event:MouseEvent) : void
        {
            ModelProxy.change("bag", "chushou", null);
            return;
        }// end function

        protected function baitanHandler(event:MouseEvent) : void
        {
            var _loc_2:* = UserData.getUserData("level");
            if (_loc_2 < 60)
            {
                WarningManager.show(30, [60, "摆摊"]);
                return;
            }
            ModelProxy.change("zone", "newstallage", null);
            return;
        }// end function

        protected function tidyHandler(event:MouseEvent) : void
        {
            if (this._timeID > 0)
            {
                return;
            }
            this.curtime = 10;
            tidybtn.disabled = true;
            this._timeID = setInterval(this.gotimeHander, 1000);
            tidybtn.label = "" + this.curtime;
            PluginManager.instance.sendToServer("bag", CMDBag.tidyItem, null);
            return;
        }// end function

        private function gotimeHander() : void
        {
            if (this.curtime > 0)
            {
                var _loc_1:String = this;
                var _loc_2:* = this.curtime - 1;
                _loc_1.curtime = _loc_2;
                tidybtn.label = "" + this.curtime;
            }
            else
            {
                clearInterval(this._timeID);
                tidybtn.label = "整理";
                tidybtn.disabled = false;
                this._timeID = 0;
                this.curtime = 10;
            }
            return;
        }// end function

        public function tidyItem(param1:Object) : void
        {
            var _loc_2:Object = null;
            var _loc_5:int = 0;
            if (param1["emptycount"])
            {
                this._emptycount = param1["emptycount"];
                _txtRemainder.text = "包裹空间: " + this._emptycount + "/" + this._usercount;
            }
            if (this._toolArray == null)
            {
                this._toolArray = new Array();
            }
            else
            {
                while (this._toolArray.length > 0)
                {
                    
                    this._toolArray.pop();
                }
            }
            this._usercount = param1.maxcount;
            this._emptycount = param1.emptycount;
            if (this._usercount > this._maxcount)
            {
                this._usercount = this._maxcount;
            }
            var _loc_3:int = 1;
            while (_loc_3 <= this._usercount)
            {
                
                if (param1[_loc_3])
                {
                    _loc_2 = param1[_loc_3];
                    _loc_2.index = _loc_3;
                    if (this._cfgitems)
                    {
                        if (_loc_2[2] == 2)
                        {
                            _loc_2[4] = this._cfgitems[_loc_2[0]];
                        }
                    }
                }
                else
                {
                    _loc_2 = new Object();
                    _loc_2.index = _loc_3;
                }
                _loc_2.lock = 0;
                this._toolArray.push(_loc_2);
                _loc_3++;
            }
            var _loc_4:* = this._maxcount - this._usercount;
            if (this._maxcount - this._usercount > 0)
            {
                _loc_5 = 1;
                while (_loc_5 <= _loc_4)
                {
                    
                    _loc_2 = new Object();
                    _loc_2.lock = 1;
                    _loc_2.index = this._usercount + _loc_5;
                    this._toolArray.push(_loc_2);
                    _loc_5++;
                }
            }
            if (param1.tbag)
            {
                this._tbagArr = param1.tbag;
                this.initTag();
            }
            this.change(this._tab);
            return;
        }// end function

        protected function getgoldHandler(event:MouseEvent) : void
        {
            DialogMgr.instance.open(AppDialog.TI_QU_YUAN_BAO);
            return;
        }// end function

        protected function shopHandler(event:MouseEvent) : void
        {
            ModelProxy.change("plugin", "change", {target:"suishenshop"});
            return;
        }// end function

        private function updateCost(param1:int, param2:int) : void
        {
            if (param1 == 1)
            {
                goldtxt.text = UIGlobel.setNumTxt(param2);
            }
            else if (param1 == 2)
            {
                bybtxt.text = UIGlobel.setNumTxt(param2);
            }
            else if (param1 == 3)
            {
                ybtxt.text = UIGlobel.setNumTxt(param2);
            }
            else if (param1 == 4)
            {
                bgoldtxt.text = UIGlobel.setNumTxt(param2);
            }
            return;
        }// end function

        public function init(param1:Object) : void
        {
            var _loc_2:Object = null;
            var _loc_5:int = 0;
            if (param1 == null)
            {
                return;
            }
            if (this._toolArray == null)
            {
                this._toolArray = new Array();
            }
            else
            {
                while (this._toolArray.length > 0)
                {
                    
                    this._toolArray.pop();
                }
            }
            this._usercount = param1.maxcount;
            this._emptycount = param1.emptycount;
            if (this._usercount > this._maxcount)
            {
                this._usercount = this._maxcount;
            }
            var _loc_3:int = 1;
            while (_loc_3 <= this._usercount)
            {
                
                if (param1[_loc_3])
                {
                    _loc_2 = param1[_loc_3];
                    _loc_2.index = _loc_3;
                    if (this._cfgitems)
                    {
                        if (_loc_2[2] == 2)
                        {
                            _loc_2[4] = this._cfgitems[_loc_2[0]];
                        }
                    }
                }
                else
                {
                    _loc_2 = new Object();
                    _loc_2.index = _loc_3;
                }
                _loc_2.lock = 0;
                this._toolArray.push(_loc_2);
                _loc_3++;
            }
            var _loc_4:* = this._maxcount - this._usercount;
            if (this._maxcount - this._usercount > 0)
            {
                _loc_5 = 1;
                while (_loc_5 <= _loc_4)
                {
                    
                    _loc_2 = new Object();
                    _loc_2.lock = 1;
                    _loc_2.index = this._usercount + _loc_5;
                    this._toolArray.push(_loc_2);
                    _loc_5++;
                }
            }
            if (param1.tbag)
            {
                this._tbagArr = param1.tbag;
                this.initTag();
            }
            else
            {
                this._tbagArr = new Object();
                this.initTag();
            }
            mlist.array = this._toolArray;
            this.bagtype = 1;
            mlist.renderHandler = new Handler(this.mlistrender);
            this.updateCost(1, param1.gold);
            this.updateCost(2, param1.bonus);
            this.updateCost(3, param1.money);
            this.updateCost(4, param1.bgold);
            _txtRemainder.text = "包裹空间: " + this._emptycount + "/" + this._usercount;
            return;
        }// end function

        public function getVip() : void
        {
            if (ItemUilt.checkVip())
            {
                openhs.visible = true;
            }
            else
            {
                openhs.visible = false;
            }
            return;
        }// end function

        private function mlistrender(param1:Component, param2:int) : void
        {
            if (param2 < mlist.length)
            {
                (param1.getChildByName("item") as BagitemCtrl).data = mlist.array[param2];
            }
            return;
        }// end function

        private function initTag() : void
        {
            var _loc_1:int = 0;
            var _loc_2:* = undefined;
            if (this._tbagArr && this._tbagArr.source.length > 0)
            {
                _loc_1 = 0;
                while (_loc_1 < this._tbagArr.source.length)
                {
                    
                    _loc_2 = this._tbagArr.source[_loc_1];
                    if (this._cfgitems)
                    {
                        _loc_2[4] = ItemObject.create(this._cfgitems[_loc_2[0]]);
                    }
                    _loc_1++;
                }
                tbag.tlist.array = this._tbagArr.source;
                tbag.tlist.renderHandler = new Handler(this.tbagItemRender);
                tbag.visible = true;
            }
            else if (tbag)
            {
                tbag.visible = false;
            }
            return;
        }// end function

        public function clickitem(param1:Point, param2:Object) : void
        {
            this._clickindex = param2.index - 1;
            var _loc_3:* = this.globalToLocal(param1);
            _useMenu.x = _loc_3.x + 10;
            _useMenu.y = _loc_3.y + 10;
            _useMenu.visible = true;
            GlobalLayer.instance.root.addEventListener(MouseEvent.CLICK, this.closemenue);
            return;
        }// end function

        public function clickitem2(param1:Object) : void
        {
            if (this.bagtype != 1)
            {
                return;
            }
            if (param1 != null)
            {
                this._clickindex = param1.index - 1;
            }
            return;
        }// end function

        public function closemenue(event:MouseEvent = null) : void
        {
            _useMenu.visible = false;
            menuelist.selectedIndex = -1;
            if (GlobalLayer.instance.root.hasEventListener(MouseEvent.CLICK))
            {
                GlobalLayer.instance.root.removeEventListener(MouseEvent.CLICK, this.closemenue);
            }
            return;
        }// end function

        private function tbagItemRender(param1:Component, param2:int) : void
        {
            if (param2 < tbag.tlist.length)
            {
                (param1 as FlashItem).data = tbag.tlist.array[param2][4];
            }
            return;
        }// end function

        public function Localupdate() : void
        {
            var _loc_2:Object = null;
            var _loc_1:int = 0;
            while (_loc_1 < mlist.length)
            {
                
                _loc_2 = mlist.getItem(_loc_1);
                mlist.changeItem(_loc_1, _loc_2);
                _loc_1++;
            }
            return;
        }// end function

        public function updateopentime() : void
        {
            if (this._tab != 1)
            {
                return;
            }
            var _loc_1:* = UserData.getBagData("maxcount");
            if (_loc_1 >= this._maxcount)
            {
                return;
            }
            var _loc_2:* = mlist.getItem(_loc_1);
            mlist.changeItem(_loc_1, _loc_2);
            return;
        }// end function

        public function toolStartCd(param1:int) : void
        {
            var _loc_5:Object = null;
            if (this._cfgtools == null)
            {
                this._cfgtools = ConfigDictionary.data.item;
            }
            var _loc_2:* = this._cfgtools[param1].pubcd;
            var _loc_3:* = UserData.getBagData();
            var _loc_4:int = 0;
            while (_loc_4 < mlist.array.length)
            {
                
                _loc_5 = mlist.array[_loc_4];
                if (_loc_5 && _loc_5.hasOwnProperty("4"))
                {
                    _loc_5 = _loc_5[4];
                    if (_loc_5 && _loc_5.hasOwnProperty("itemid"))
                    {
                        if (_loc_5.pubcd == _loc_2)
                        {
                            this.startCd(_loc_4);
                        }
                    }
                }
                _loc_4++;
            }
            return;
        }// end function

        private function startCd(param1:int) : void
        {
            var _loc_2:* = mlist.getItem(param1);
            _loc_2.showcd = 1;
            mlist.changeItem(param1, _loc_2);
            return;
        }// end function

        public function kuorong(param1:int = 1) : void
        {
            var _loc_2:Object = null;
            this._emptycount = this._emptycount + param1;
            _txtRemainder.text = "包裹空间: " + this._emptycount + "/" + this._usercount;
            var _loc_3:int = 0;
            while (_loc_3 < param1)
            {
                
                _loc_2 = mlist.getItem(this._usercount + _loc_3);
                _loc_2.lock = 0;
                this.changeItemByIndex(this._usercount + _loc_3, _loc_2);
                this._toolArray[this._usercount + _loc_3] = _loc_2;
                _loc_3++;
            }
            if (this._usercount + param1 < this._maxcount)
            {
                _loc_2 = mlist.getItem(this._usercount + param1);
                this._toolArray[param1 + this._usercount] = _loc_2;
                this.changeItemByIndex(this._usercount + param1, _loc_2);
            }
            this._usercount = this._usercount + param1;
            return;
        }// end function

        public function UpdateDurables(param1:Object) : void
        {
            var _loc_2:String = null;
            var _loc_3:int = 0;
            var _loc_4:Object = null;
            for (_loc_2 in param1)
            {
                
                _loc_3 = 1;
                while (_loc_3 <= this._usercount)
                {
                    
                    _loc_4 = this._toolArray[(_loc_3 - 1)];
                    if (_loc_4 && _loc_2 == _loc_4[0])
                    {
                        _loc_4[4].durable = param1[_loc_2];
                        this._toolArray[(_loc_3 - 1)] = _loc_4;
                        this.changeItemByIndex((_loc_3 - 1), _loc_4);
                        break;
                    }
                    _loc_3++;
                }
            }
            return;
        }// end function

        public function addItem(param1:Object) : void
        {
            var _loc_4:String = null;
            var _loc_5:int = 0;
            var _loc_6:Object = null;
            var _loc_7:Object = null;
            var _loc_8:Object = null;
            var _loc_2:* = UserData.getBagData();
            var _loc_3:int = 0;
            if (param1.itemeffect)
            {
                _loc_3 = param1.itemeffect;
            }
            for (_loc_4 in param1)
            {
                
                if (_loc_4 == "bonus")
                {
                    this.updateCost(2, param1[_loc_4]);
                    continue;
                }
                if (_loc_4 == "gold")
                {
                    this.updateCost(1, param1[_loc_4]);
                    continue;
                }
                if (_loc_4 == "money")
                {
                    this.updateCost(3, param1[_loc_4]);
                    continue;
                }
                if (_loc_4 == "bgold")
                {
                    this.updateCost(4, param1[_loc_4]);
                    continue;
                }
                if (_loc_4 == "intel")
                {
                    continue;
                }
                if (_loc_4 == "tbag")
                {
                    this._tbagArr = param1[_loc_4] as Object;
                    this.initTag();
                    continue;
                }
                if (_loc_4 == "maxcount")
                {
                    this.kuorong(param1[_loc_4] - this._usercount);
                    this._usercount = param1[_loc_4];
                    _txtRemainder.text = "包裹空间: " + this._emptycount + "/" + this._usercount;
                    continue;
                }
                if (_loc_4 == "emptycount")
                {
                    this._emptycount = param1[_loc_4];
                    _txtRemainder.text = "包裹空间: " + this._emptycount + "/" + this._usercount;
                    continue;
                }
                if (_loc_4 == "contribution")
                {
                    _loc_5 = param1[_loc_4] - _loc_2.contribution;
                    _loc_2.contribution = param1[_loc_4];
                    ModelProxy.change("unionDonate", "updateContribution", _loc_5);
                    ModelProxy.change("union", "updateContribution", null);
                    continue;
                }
                if (int(_loc_4) > 0 && int(_loc_4) <= this._maxcount)
                {
                    _loc_6 = param1[_loc_4];
                    if (_loc_6 == null)
                    {
                        _loc_7 = new Object();
                        _loc_7.index = _loc_4;
                        _loc_7.lock = 0;
                        this._toolArray[(int(_loc_4) - 1)] = _loc_7;
                        this.changeItemByIndex((int(_loc_4) - 1), _loc_7, _loc_3);
                        continue;
                    }
                    _loc_8 = null;
                    if (this._cfgitems)
                    {
                        if (_loc_6 && _loc_6[2] == 2)
                        {
                            _loc_8 = this._cfgitems[_loc_6[0]];
                            _loc_6[4] = _loc_8;
                        }
                    }
                    _loc_6.index = _loc_4;
                    this._toolArray[(int(_loc_4) - 1)] = _loc_6;
                    this.changeItemByIndex((int(_loc_4) - 1), _loc_6);
                }
            }
            return;
        }// end function

        public function DragOver(param1:Object, param2:Point, param3:String) : void
        {
            var _loc_4:* = this.globalToLocal(param2);
            if (this.globalToLocal(param2).x > 0 && _loc_4.y > 0 && _loc_4.x < this.width && _loc_4.y < this.height)
            {
                if (param3 == "warehouse")
                {
                    this.storeToBag(param1, param2);
                }
            }
            return;
        }// end function

        private function storeToBag(param1:Object, param2:Point) : void
        {
            var _loc_3:* = this.globalToLocal(param2);
            if (_loc_3.x < 11 || _loc_3.y < 62 || _loc_3.x > 340 || _loc_3.y > 345)
            {
                return;
            }
            PluginManager.instance.sendToServer("warehouse", CMDStorehouse.Tackout, param1.param);
            return;
        }// end function

        public function businessAddItem(param1:Array) : void
        {
            var _loc_2:int = 0;
            var _loc_4:Object = null;
            var _loc_5:Object = null;
            var _loc_3:* = UserData.getBagData();
            _loc_2 = 1;
            while (_loc_2 <= this._usercount)
            {
                
                _loc_4 = _loc_3[_loc_2];
                if (_loc_4)
                {
                    _loc_4.isbusiness = false;
                    this.changeItemByIndex(_loc_2, _loc_4);
                }
                _loc_2++;
            }
            if (param1)
            {
                for each (_loc_5 in param1)
                {
                    
                    if (_loc_5)
                    {
                        if (_loc_5.index >= 0)
                        {
                            _loc_4 = _loc_3[_loc_5.index];
                            if (_loc_4)
                            {
                                _loc_4.isbusiness = true;
                                this.changeItemByIndex(_loc_5.index, _loc_4);
                            }
                        }
                    }
                }
            }
            return;
        }// end function

        public function changeItemByIndex(param1:int, param2:Object, param3:int = 0) : void
        {
            var _loc_5:String = null;
            var _loc_6:String = null;
            var _loc_7:int = 0;
            var _loc_8:int = 0;
            var _loc_4:Boolean = false;
            if (this._tab == 1)
            {
                _loc_4 = true;
            }
            else if (this._tab == 2)
            {
                if (param2 && param2[4] && param2[4].itemtype == 1)
                {
                    _loc_4 = true;
                }
            }
            else if (this._tab == 3)
            {
                _loc_5 = "";
                if (param2 && param2[4])
                {
                    _loc_5 = param2[4].itemid + "";
                }
                _loc_6 = _loc_5.substr(0, 3);
                if (param2 && param2[4] && param2[4].itemtype == 2 && param2[4].leixing == "药品")
                {
                    _loc_4 = true;
                }
            }
            else if (this._tab == 4)
            {
                _loc_5 = "";
                if (param2 && param2[4])
                {
                    _loc_5 = param2[4].itemid + "";
                }
                _loc_6 = _loc_5.substr(0, 3);
                if (param2[4] && param2[4].itemtype == 2 && param2[4].leixing != "药品" && param2[4].leixing != "其他")
                {
                    _loc_4 = true;
                }
            }
            else if (this._tab == 5)
            {
                _loc_5 = "";
                if (param2 && param2[4])
                {
                    _loc_5 = param2[4].itemid + "";
                }
                _loc_6 = _loc_5.substr(0, 3);
                if (param2[4] && param2[4].itemtype == 2 && param2[4].leixing == "其他")
                {
                    _loc_4 = true;
                }
            }
            if (!_loc_4 && param2[4])
            {
                return;
            }
            if (this._tab == 1)
            {
                _loc_7 = 0;
                while (_loc_7 < mlist.length)
                {
                    
                    if (mlist.array[_loc_7] && mlist.array[_loc_7].index == param2.index)
                    {
                        if (param2.index > mlist.startIndex && param2.index < mlist.startIndex + mlist.cells.length)
                        {
                            param2.param = param3;
                        }
                        mlist.changeItem(_loc_7, param2);
                        break;
                    }
                    _loc_7++;
                }
            }
            else
            {
                this.change(this._tab);
                return;
            }
            return;
        }// end function

    }
}
